<?php 
ini_set('display_errors', 1); 
ini_set('error_reporting', 'E_error');
 require_once "../includes/config.php";
 ?>
 <script type="text/javascript">
 function update_service(wishlist_id)
 {
	window.location="index.php?edit_mwishlist&wishlist_id="+wishlist_id;
 }
 function funDelMem(userId)
 {
	var delPro=confirm("Are you sure want to delete wishlist?");
    if(delPro==true) {
		var frm = document.getElementById('form1');
		document.getElementById("hidDelMember").value=userId;
	    frm.submit();
	}	
}
 </script>
 <?
 if(!empty($_POST['hidDelMember']))
{
	$memberId=$_POST['hidDelMember'];
	$sqlDelMem="Delete from tbl_whole_wishlist where wishlist_id=$memberId";
	$rstDelMem=mysql_query($sqlDelMem);	
}
$cond = '';
$sort = '';
$ut = $u = $fn = $ln = $dg = 'asc';
if(isset($_GET['sort']))
{
 if($_GET['sort']=='product_name')
 {
  if($_GET['s_type']=='asc')
  {	$cond=' ORDER BY product_name ASC';	$sort = '&sort=product_name&s_type=asc';	$ut='desc';	}
  else
  {	$cond=' ORDER BY product_name DESC';	$sort = '&sort=product_name&s_type=desc';	}
 }
 else if($_GET['sort']=='price')
 {
  if($_GET['s_type']=='asc')
  {	$cond=' ORDER BY price ASC';	$sort = '&sort=price&s_type=asc';	$ut='desc';	}
  else
  {	$cond=' ORDER BY price DESC';	$sort = '&sort=price&s_type=desc';	}
 }
}
?>
<form action="" method="post" name="form1" id="form1" name="formService" id="formService">
       <input type="hidden" name="hidDelMember" id="hidDelMember">
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Wishlist(Buyer) <span style="text-align:right; padding-left:350px;"></span></td>
  </tr>  
  <tr>
    <td height="577">	
	<table width="100%">
			    <tbody>
				   <tr>
					  <td>
						 <form name="frmSearchPro" action="" method="post">
							<table width="100%" border="0">
							       <tr>
								      <td width="20%">Product Name</td>
								      <td width="30%">
									      <input type="text" name="product_name" id="product_name" style="width: 150px;" value="<?php echo $_POST['product_name']?>" />
								      </td>
								      <td width="20%">Price</td>
								      <td width="30%"><input type="text" name="pro_price" id="pro_price" style="width: 150px;" value="<?php echo $_POST['pro_price']?>" /></td>
							       </tr>
							       <tr>
								      <td width="20%">Category</td>
								      <td width="30%">
									      <input type="text" name="cat_name" id="cat_name" style="width: 150px;" value="<?php echo $_POST['cat_name']?>" />
								      </td>
								      <td width="20%">&nbsp;</td>
								      <td width="30%">&nbsp;</td>
							       </tr>
				  
							       <tr>
								       <td height="35" colspan="5" style="text-align:center"><input type="submit" name="btnSearchPro" value="Search" /></td>
							       </tr>
							</table>
						 </form>
					  </td>
				   </tr>
				   <tr>
					  <td>
						 <b>Sort  By :</b>
						 <a href="<?php echo $base_url;?>admin/index.php?list_mwishlist&sort=product_name&s_type=<?php echo $ut;?>">Product Name</a> &nbsp;&nbsp;&nbsp;
						 <a href="<?php echo $base_url;?>admin/index.php?list_mwishlist&sort=price&s_type=<?php echo $ut;?>">Product Price</a> &nbsp;&nbsp;&nbsp;
					  </td>
				   </tr>
			    </tbody>
      </table><br>
	<table width="100%"  border="0" cellspacing="0">
	  
	 <tr class="InnerHeader">
	   <td width="1%"  class="line">&nbsp;</td>
	   <td width="40%" class="line">ProductName</td>
	   <td width="41%" class="line">Category</td>
	   <td width="41%" class="line">Price</td>
	   <td width="41%" class="line">Description</td>
	   <td width="9%" class="line"></td>
	   <td width="9%" class="line"></td>
	 </tr>	 
	 <?php
	 
			    $search='';
			    if(isset($_POST['btnSearchPro'])) {
				    
				    $product_name 	= $_POST['product_name'];		
				    $price 		    = $_POST['pro_price'];
					$cat_name       = $_POST['cat_name'];
				   
				   
				   if($cat_name!='')
				   $search.= " AND cat_id IN (select wanted_cat_id from tb1_wanted_category where cat_name LIKE '%$cat_name%')";

				    
				   if($product_name!='')
				   $search.= " AND product_name='".$product_name."'";
				   
				   if($product_name!='') {
					  if($price!='')
						 $search.=" AND price='".$price."'";
				   }
				   else {
					  if($price!='')
						 $search.=" AND price='".$price."'";
				   }
			    }
				
		 	  $sqlShwSubcat="select * from tbl_whole_wishlist where 1=1  $search $cond";
			  //echo $sqlShwSubcat;
			  $rstShwSubcat=mysql_query($sqlShwSubcat);
			  $numShwSubcat=mysql_num_rows($rstShwSubcat);
			  if($numShwSubcat==0) 
			  {
				 echo "<tr><td></td><td colspan='4'><h3>No Wishlist Found...</h3></td></tr>";
			  }
			  else 
			  {
			  while($rowShwSubCat=mysql_fetch_array($rstShwSubcat)) 
			  {
				 $wishlist_id=$rowShwSubCat['wishlist_id'];
				 $product_name=$rowShwSubCat['product_name'];
				 $description=$rowShwSubCat['description'];
				 $price=$rowShwSubCat['price'];
				 
				 $arrCategory=mysql_fetch_array(mysql_query("SELECT * FROM tb1_wanted_category WHERE wanted_cat_id='".$rowShwSubCat['cat_id']."'"));
				 $category=stripslashes($arrCategory['cat_name']);
				 
				 echo "<tr>";
				 echo "<td class='line'>&nbsp;</td>";
				 echo "<td class='line'>$product_name</td>";
				 echo "<td class='line'>$category</td>";
				 echo "<td class='line'>$price</td>";
				 echo "<td class='line'>$description</td>";
				 echo "<td class='line'><input type='button' name='edit' value='Edit' class='button' onclick='update_service($wishlist_id);'></td>";
				 echo "<td height='20' class='line'><input type='button' name='delete' value='Delete' class='button'  onclick='funDelMem($wishlist_id)';></td> ";
				 echo "<td height='20' class='line'></td> ";
				 echo "</tr>";
			  }
			  }
		 ?>
	 <tr>
		   <td>&nbsp;</td>
		   <td>&nbsp;</td>
		   <td>&nbsp;</td>
		   <td>&nbsp;</td>
		   <td></td>
		   <td></td>
		   <td></td>
	  </tr>
	</table>
</td>
</tr>
</table>
</form>